#include <iostream>
#include "list"

using namespace std;

/*
 * 对person进行排序，按照年龄进行升序，年龄相同按照身高进行降序
 */

class Person{
public:
    string p_name;
    int p_age;
    int p_tall;
    Person(string name, int age, int tall){
        this->p_name = name;
        this->p_age = age;
        this->p_tall = tall;
    }
};

void myPrint(list<Person> lst){
    for (list<Person>::iterator it= lst.begin(); it!= lst.end() ; ++it) {
        cout << "姓名：" << it->p_name << ", 年龄:" << it->p_age << ", 身高: " <<it->p_tall << endl;
    }
}

bool myCompare(Person & p1, Person & p2){
    if(p1.p_age > p2.p_age){
        return false;
    }else if(p1.p_age < p2.p_age){
        return true;
    } else{
        if(p1.p_tall>p2.p_tall){
            return true;
        }else{
            return false;
        }
    }
}

void test01(){
    Person p1("A", 18, 160);
    Person p2("B", 15, 160);
    Person p3("C", 18, 170);
    Person p4("D", 20, 190);
    Person p5("E", 15, 170);

    list<Person> lst;
    lst.push_back(p1);
    lst.push_back(p2);
    lst.push_back(p3);
    lst.push_back(p4);
    lst.push_back(p5);

    myPrint(lst);
    lst.sort(myCompare);
    cout << "排序后" << endl;

    myPrint(lst);
}

int main() {

    test01();

    return 0;
}
